[#ftl]
[#import "common/macrolibs.ftl" as lib]
[#assign mtmtable][@lib.mtmTableName  mtm=relation/][/#assign]
[#assign mtmalias]mtm${relation.id}[/#assign]
[#assign masterid]t${master.id}mid[/#assign]
[#assign  slaveid]t${slave.id}sid[/#assign]
[#assign masteralias]t${master.id}[/#assign]
[#assign slavealias]t${slave.id}[/#assign]
[#assign fkmaster]FK_${mtmalias}_${masterid}_${masteralias}[/#assign]
[#assign fkslave]FK_${mtmalias}_${slaveid}_${slavealias}[/#assign]
CREATE TABLE `${mtmtable}` (
  `${masterid}` int(10) unsigned NOT NULL,
  `${slaveid}` int(10) unsigned NOT NULL,
  PRIMARY KEY (`${masterid}`,`${slaveid}`),
  KEY `${fkmaster}` (`${masterid}`),
  KEY `${fkslave}` (`${slaveid}`),
  CONSTRAINT `${fkmaster}` FOREIGN KEY (`${masterid}`) REFERENCES `[@lib.fullTableName clazz=relation.master/]` (`id`),
  CONSTRAINT `${fkslave}` FOREIGN KEY (`${slaveid}`) REFERENCES `[@lib.fullTableName clazz=relation.slave/]` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

